package com.study.samsung.Control.htControl;

import com.study.samsung.Entity.Commodity;
import com.study.samsung.Entity.Commoditycolor;
import com.study.samsung.Entity.Commoditymemory;
import com.study.samsung.Entity.Detail;
import com.study.samsung.Service.CommodityService;
import com.study.samsung.Service.CommoditycolorService;
import com.study.samsung.Service.DetailService;
import com.study.samsung.Utils.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

@WebServlet("/goodsxq")
public class GoodsxqServlet extends BaseServlet {
    DetailService ds = new DetailService();
    CommoditycolorService ccs = new CommoditycolorService();
    CommodityService cos = new CommodityService();
    @Override
    public String excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        Object obj = session.getAttribute("admin");
        if (obj==null){
            return "f:htjsp/login";
        }else {
            String Sid = request.getParameter("sid");
            System.out.println(Sid);
            Integer sid = Integer.parseInt(Sid);
            List<Detail> details = ds.selectAll(sid);
            session.setAttribute("goodsxq",details);
            System.out.println("商品详情查询到的所有内容"+details);
            return "f:/htjsp/goodsxq";
        }

    }

    public Integer delgoodsxq(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String id = request.getParameter("id");
        System.out.println("要删除的商品详情的id="+id);
        int i = Integer.parseInt(id);
        Integer delgoodsxq = ds.delgoodsxq(i);
        return delgoodsxq;
    }

    public String addgoodsxq(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String Sid = request.getParameter("sid");
        Integer sid = Integer.parseInt(Sid);
        List<Detail> details = ds.selectAll(sid);
        session.setAttribute("details",details);
        System.out.println("通过商品id查到的详情："+details);
        List<Commodity> commodities = cos.htselectByid(sid);
        System.out.println("通过id查询到的商品："+commodities);
        session.setAttribute("commodities",commodities);
        List<Commoditycolor> commoditycolors = ccs.selectAll();
        session.setAttribute("commoditycolors",commoditycolors);
        List<Commoditymemory> commoditymemories = ccs.selectmemoryAll();
        session.setAttribute("commoditymemories",commoditymemories);
        return  "f:/htjsp/goodsxqadd";
    }
    public Integer goodsxqadd(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");

        String Xprice = request.getParameter("xprice");
        System.out.println(Xprice);
        double xprice = Double.parseDouble(Xprice);
        Integer yid = Integer.parseInt(request.getParameter("yid"));
        Integer nid = Integer.parseInt(request.getParameter("nid"));
        Integer sid = Integer.parseInt(request.getParameter("sid"));
        Integer insertgoodsxq = ds.insertgoodsxq(xprice, yid, nid, sid);
        return insertgoodsxq;
    }

    public String shuaxin(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String Sid = request.getParameter("sid");
        Integer sid = Integer.parseInt(Sid);
        List<Detail> details = ds.selectAll(sid);
        session.setAttribute("details",details);
        return "shuaxin";
    }
}
